<?php
namespace Common\Model;
use Think\Model;

/*
 * 文章内容model
 * @auth suosuo
 */

 class NewsContentModel extends Model {
 	private $_db = '';
	
	public function __construct(){
		$this->_db = M('news_content');
	}
	
	public function insert ($data = array()) {
		if(!is_array($data) || !$data){
			return 0;
		}
		$data['create_time'] = time();
		if(isset($data['content']) && $data['content']){
			$data['content'] = htmlspecialchars($data['content']);
		}
		return $this->_db->add($data);
	}
	
	public function getNewsById ($id){
		if(!is_numeric($id) || !$id){
			throw_exception("ID不合法");
		}
		$data = $this ->_db->where('news_id='.$id)->find();
		return $data;
	}
	public function updataById ($id,$data) {
		if(!$id || !is_numeric($id)){
			throw_exception("ID不合法");			
		}
		if(!$data || !is_array($data)){
			throw_exception("更新内容不合法");
		}
		if(isset($data['content']) && $data['content']){
			$data['content'] = htmlspecialchars($data['content']);
		}
		return $this->_db->where('news_id='.$id)->save($data);
	}
 }
